<template>
  <view class="txbox">
    <view class="je"><view class="" style="margin: 0 10rpx;">可提现金额</view><view style="color: #04BABE;font-size: 55rpx;">{{jewallet}}</view></view>
    <view class="tx-title">
      <input class="txinput" type="number" v-model="money" @blur="verify" placeholder="请输入提现金额"/>
      <view class="">
        <button class="txbtn" @click="alltx">全部提现</button>
      </view>
    </view>
    <view class="" style="width: 90%;margin:40rpx auto 20rpx auto;font-size: 35rpx;">
      <view class="">请上传微信或支付宝收款码</view>
      <view class="yard">
          <button class="scbtn"  @tap="chooseImage">点击上传</button>
       <!--   <view class="" style="text-align: center;margin-top: 40rpx;">
            <image class="imgyar" :src="yarimage" mode=""></image>
          </view> -->
      </view>
    <!--  <view class="">
        <button class="scbtn"  @click="uploadimage">立即提现</button>
      </view> -->
    </view>
  </view>
</template>

<script>
  export default{
    onShow() {
      this.getmoney()
    },
    data() {
      return {
        jewallet:'',
        money:'',
        yarimage:''
      }
    },
    methods:{
      getmoney() {
        uni.request({
        	url: getApp().globalData.apiDomain+'/wallet/mywallet',
        	method: 'POST',
        	header: {
        		'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
        		'token': uni.getStorageSync('wbyun_token'),
            'wbapp':'weixin_mp_xbgy'
        	},
        	data: {},
        	dataType: 'json',
        	success:  res => {
            console.log(res);
        		if (res['data']['code'] == 200) {
              this.jewallet = res.data.datas.wallet
        			return;   
        		} else { 
        			uni.showToast({
        				title: res['data']['msg'],
        				icon: 'none'
        			});
              
        		}
        	},
        	fail: () => {},
        	complete: () => {
        	}
        });
      },
      alltx() {
        this.money = this.jewallet
        
      },
      verify() {
        console.log(2222,Number(this.jewallet));
        if(this.money > Number(this.jewallet)){
          uni.showToast({
            	title: '金额大于可提现金额！',
            	icon: 'none'
            });
        }
        
      },
      chooseImage() {
        if(this.money == '') {
          uni.showToast({
            	title: '请先输入提现金额!',
            	icon: 'none'
            });
            return
        }else if(this.money > Number(this.jewallet)) {
          uni.showToast({
           	title: '金额大于可提现金额！',
           	icon: 'none'
           });
           return
        }
        var that = this
        uni.chooseImage({          count: 1, //默认9          sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有          sourceType: ['album'], //从相册选择          success: function (res) {
            console.log(res);            console.log(JSON.stringify(res.tempFilePaths));
          
           uni.getFileSystemManager().readFile({
                 filePath: res.tempFilePaths[0], //照片的临时地址
                 encoding: "base64", //编码格式
                 success: (nres) => {
                     let data="data:image/jpg" +";base64," +nres.data //base64地址
                     console.log(data);
                     //后续操作
                     uni.uploadFile({
                     			url: getApp().globalData.apiDomain+'wallet/withdraw', //仅为示例，非真实的接口地址
                          header: {
                          'token':uni.getStorageSync('wbyun_token'),
                          'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
                          'wbapp':'weixin_mp_xbgy'
                          },
                     			name: 'file',
                          filePath:res.tempFilePaths[0],
                     			formData: {
                     				'price': that.money,
                            'paycode':data
                     			},
                     			success: (uploadFileRes) => {
                     			let data = 	JSON.parse(uploadFileRes.data)
                          console.log(data);
                            uni.showToast({
                              	title: data['msg'],
                              	icon: 'none'
                              });
                              that.getmoney()
                              that.money = ''
                     			}
                     		});
                     
                 },
                 fail: (res) => reject(res.errMsg),
            })
         
          
        
          }        });
      },
      uploadimage() {
        console.log('1111');
      
     uni.getFileSystemManager().readFile({
           filePath: this.yarimage, //照片的临时地址
           encoding: "base64", //编码格式
           success: (nres) => {
               let data="data:image/jpg" +";base64," +nres.data //base64地址
               //后续操作
               
               uni.uploadFile({
               			url: getApp().globalData.apiDomain+'wallet/withdraw', //仅为示例，非真实的接口地址
                    header: {
                    'token':uni.getStorageSync('wbyun_token'),
                    'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
                    'wbapp':'weixin_mp_xbgy'
                    },
               			name: 'file',
                    filePath:this.yarimage,
               			formData: {
               				'price': this.money,
                      'paycode':data
               			},
               			success: (uploadFileRes) => {
               				console.log(uploadFileRes.data);
               			}
               		});
               
           },
           fail: (res) => reject(res.errMsg),
      })
     
        
      }
   
    }
  }
</script>

<style>
  .txbox {
    width: 95%;
    height: 90vh;
    background-color: #fff;
    border-radius: 10rpx;
    margin: 20rpx auto 0 auto;
    padding: 10rpx;
  }
  .tx-title {
    width: 90%;
    margin: 40rpx auto 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 35rpx;
  }
  .je {
   
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 50rpx;
    font-size: 40rpx;
  }
  .txinput {
        width: 370rpx;
        height: 90rpx;
        padding-left: 20rpx;
        font-size: 32rpx;
        border-radius: 15rpx;
        background-color: rgb(246,246,246);
  }
  .txbtn {
    width: 200rpx;
    height: 80rpx;
    line-height: 80rpx;
    background-color: #04BABE;
    color: #fff;
    border-radius: 10rpx;
    font-size: 30rpx;
    padding: 0;
  }
  .yard {
    margin-top: 40rpx;
    
  }
  .scbtn {
    margin-top: 40rpx;
    border-radius: 10rpx;
    background-color: #04BABE;
    color: #fff;
    border: 0;
  }
  .imgyar {
    width: 200rpx;
    height: 250rpx;
    background-color: #e5e5e5;
  }
</style>